﻿#include <iostream>
#include <thread>

#include <zmq.hpp>
#include <spdlog/spdlog.h>

int main()
{
	zmq::context_t ctx;
	zmq::socket_t pusher = zmq::socket_t(ctx, ZMQ_PUSH);
	pusher.bind("tcp://*:5557");

	zmq::socket_t sink_notifier = zmq::socket_t(ctx, ZMQ_PUSH);
	sink_notifier.connect("tcp://localhost:5558");

	std::cout << "Enter any key when the workers are ready: " << std::endl;
	int tmp;
	std::cin >> tmp;
	std::cout << "Sending tasks to workers..." << std::endl;

	sink_notifier.send("0", 1);

	int total_msc = 0;
	for (int i = 0; i < 100; ++i)
	{
		int workload = std::rand() % 100 + 1;
		std::string msg = fmt::format("{}", workload);
		total_msc += workload;
		pusher.send(msg.data(), msg.size());
	}
	std::cout << "Total expected cost: " << total_msc << " msec" << std::endl;

	std::cin >> tmp;
;}